// =====================================================================================
// Copyright ?2006 SmartCodeGenerator created by Shahed Khan. 
/*
//Microsoft Shared Source Community License (MS-CL)
//Published: October 18, 2005
*/
// If you like this code then feel free to go ahead and use it.
// Your use of this software is entirely at your own risk.
// I make no claims or warrantees about the reliability or fitness of this code for any particular purpose.
// website www.smartcodegenerator.com, email shahed.khan@gmail.com
// =====================================================================================

using System;
using System.Configuration;
using System.Data;

namespace SmartCodeGen.Providers 
{
	public class DBSchema
    {
        #region DBSchema Methods
        public static ParameterSchemaCollection GetCommandParameters( CommandSchema command)
        {            
            //return DBSchemaProvider.Instance().GetCommandParameters( command);
            if (command.DatabaseSchemaProvider != null)
                return DBSchemaProvider.Instance(command.DatabaseSchemaProvider).GetCommandParameters(command);
            else
                return DBSchemaProvider.Instance().GetCommandParameters(command);
        }
        public static CommandResultSchemaCollection GetCommandResultSchemas( CommandSchema command)
        {
            //return DBSchemaProvider.Instance().GetCommandResultSchemas( command);
            if (command.DatabaseSchemaProvider != null)
                return DBSchemaProvider.Instance(command.DatabaseSchemaProvider).GetCommandResultSchemas(command);
            else
                return DBSchemaProvider.Instance().GetCommandResultSchemas(command);
        }
        public static CommandSchemaCollection GetCommands( DatabaseSchema database)
        {
            //return DBSchemaProvider.Instance().GetCommands( database);
            if (database.DatabaseSchemaProvider != null)
                return DBSchemaProvider.Instance(database.DatabaseSchemaProvider).GetCommands(database);
            else
                return DBSchemaProvider.Instance().GetCommands(database);
        }
        public static string GetCommandText( CommandSchema command)
        {
            //return DBSchemaProvider.Instance().GetCommandText( command);
            if (command.DatabaseSchemaProvider != null)
                return DBSchemaProvider.Instance(command.DatabaseSchemaProvider).GetCommandText(command);
            else
                return DBSchemaProvider.Instance().GetCommandText(command);
        }
        public static string GetDatabaseName(DatabaseSchema database)
        {
            //return DBSchemaProvider.Instance().GetDatabaseName(connectionString);
            if (database.DatabaseSchemaProvider != null)
                return DBSchemaProvider.Instance(database.DatabaseSchemaProvider).GetDatabaseName(database);
            else
                return DBSchemaProvider.Instance().GetDatabaseName(database);
        }
        public static ExtendedPropertyCollection GetExtendedProperties( SchemaBase schemaObject)
        {
            //return DBSchemaProvider.Instance().GetExtendedProperties( schemaObject);
            if (schemaObject.DatabaseSchemaProvider != null)
                return DBSchemaProvider.Instance(schemaObject.DatabaseSchemaProvider).GetExtendedProperties(schemaObject);
            else
                return DBSchemaProvider.Instance().GetExtendedProperties(schemaObject);

        }
        public static ColumnSchemaCollection GetTableColumns( TableSchema table)
        {
            //return DBSchemaProvider.Instance().GetTableColumns( table);
            if (table.DatabaseSchemaProvider != null)
                return DBSchemaProvider.Instance(table.DatabaseSchemaProvider).GetTableColumns(table);
            else
                return DBSchemaProvider.Instance().GetTableColumns(table);

        }
        public static DataTable GetTableData( TableSchema table)
        {
            //return DBSchemaProvider.Instance().GetTableData( table);

            if (table.DatabaseSchemaProvider != null)
                return DBSchemaProvider.Instance(table.DatabaseSchemaProvider).GetTableData(table);
            else
                return DBSchemaProvider.Instance().GetTableData(table);
        }
        public static IndexSchemaCollection GetTableIndexes( TableSchema table)
        {
            //return DBSchemaProvider.Instance().GetTableIndexes( table);
            if (table.DatabaseSchemaProvider != null)
                return DBSchemaProvider.Instance(table.DatabaseSchemaProvider).GetTableIndexes(table);
            else
                return DBSchemaProvider.Instance().GetTableIndexes(table);
        }
        public static TableKeySchemaCollection GetTableKeys( TableSchema table)
        {
            //return DBSchemaProvider.Instance().GetTableKeys( table);
            if (table.DatabaseSchemaProvider != null)
                return DBSchemaProvider.Instance(table.DatabaseSchemaProvider).GetTableKeys(table);
            else
                return DBSchemaProvider.Instance().GetTableKeys(table);
        }
        public static PrimaryKeySchema GetTablePrimaryKey( TableSchema table)
        {
            //return DBSchemaProvider.Instance().GetTablePrimaryKey(table);
            if (table.DatabaseSchemaProvider != null)
                return DBSchemaProvider.Instance(table.DatabaseSchemaProvider).GetTablePrimaryKey(table);
            else
                return DBSchemaProvider.Instance().GetTablePrimaryKey(table);

        }
        public static TableSchemaCollection GetTables( DatabaseSchema database)
        {
            //return DBSchemaProvider.Instance().GetTables( database);
            if (database.DatabaseSchemaProvider != null)
                return DBSchemaProvider.Instance(database.DatabaseSchemaProvider).GetTables(database);
            else
                return DBSchemaProvider.Instance().GetTables(database);

        }
        public static ViewColumnSchemaCollection GetViewColumns( ViewSchema view)
        {
            //return DBSchemaProvider.Instance().GetViewColumns( view);
            if (view.DatabaseSchemaProvider != null)
                return DBSchemaProvider.Instance(view.DatabaseSchemaProvider).GetViewColumns(view);
            else
                return DBSchemaProvider.Instance().GetViewColumns(view);

        }
        public static DataTable GetViewData( ViewSchema view)
        {
            //return DBSchemaProvider.Instance().GetViewData( view);
            if (view.DatabaseSchemaProvider != null)
                return DBSchemaProvider.Instance(view.DatabaseSchemaProvider).GetViewData(view);
            else
                return DBSchemaProvider.Instance().GetViewData(view);
        }
        public static ViewSchemaCollection GetViews( DatabaseSchema database)
        {
            //return DBSchemaProvider.Instance().GetViews( database);
            if (database.DatabaseSchemaProvider != null)
                return DBSchemaProvider.Instance(database.DatabaseSchemaProvider).GetViews(database);
            else
                return DBSchemaProvider.Instance().GetViews(database);
        }
        public static string GetViewText( ViewSchema view)
        {
            //return DBSchemaProvider.Instance().GetViewText( view);
            if (view.DatabaseSchemaProvider != null)
                return DBSchemaProvider.Instance(view.DatabaseSchemaProvider).GetViewText(view);
            else
                return DBSchemaProvider.Instance().GetViewText(view);

        }
        #endregion

        // Properties
        public static string GetDescription() 
        {
            return DBSchemaProvider.Instance().GetDescription();
        }
        public static string GetName() 
        {
            return DBSchemaProvider.Instance().GetName();
        }
	}
}
